
// import oimo.common.MathUtil;
// import oimo.common.Vec3;
// import oimo.dynamics.rigidbody.RigidBody;

import { JointConfig } from "./JointConfig";
import { Vec3 } from "../../../common/Vec3";
import { SpringDamper } from "./SpringDamper";
import { RotationalLimitMotor } from "./RotationalLimitMotor";
import { MathUtil } from "../../../common/MathUtil";
import { RigidBody } from "../../rigidbody/RigidBody";

/**
 * A ragdoll joint config is used for constructions of ragdoll joints.
 */
export class RagdollJointConfig extends JointConfig {
	/**
	 * The first body's local twist axis.
	 */
	 localTwistAxis1:Vec3;

	/**
	 * The second body's local twist axis.
	 */
	 localTwistAxis2:Vec3;

	/**
	 * The first body's local swing axis.
	 *
	 * The second swing axis is also attached to the first body. It is perpendicular to the first swing
	 * axis, and is automatically computed when the joint is created.
	 */
	 localSwingAxis1:Vec3;

	/**
	 * The rotational spring and damper along the twist axis of the joint.
	 */
	 twistSpringDamper:SpringDamper;

	/**
	 * The rotational limit and motor along the twist axis of the joint.
	 */
	 twistLimitMotor:RotationalLimitMotor;

	/**
	 * The rotational spring and damper along the swing axis of the joint.
	 */
	 swingSpringDamper:SpringDamper;

	/**
	 * The max angle of rotation along the first swing axis.
	 * This value must be positive.
	 */
	 maxSwingAngle1:number;

	/**
	 * The max angle of rotation along the second swing axis.
	 * This value must be positive.
	 */
	 maxSwingAngle2:number;

	/**
	 * Default constructor.
	 */
	constructor() {
		super();
		this.localTwistAxis1 = new Vec3(1, 0, 0);
		this.localTwistAxis2 = new Vec3(1, 0, 0);
		this.localSwingAxis1 = new Vec3(0, 1, 0);
		this.twistSpringDamper = new SpringDamper();
		this.swingSpringDamper = new SpringDamper();
		this.twistLimitMotor = new RotationalLimitMotor();
		this.maxSwingAngle1 = MathUtil.PI;
		this.maxSwingAngle2 = MathUtil.PI;
	}

	/**
	 * Sets rigid bodies, local anchors from the world anchor `worldAnchor`, local twist axes
	 * from the world twist axis `worldTwistAxis`, local swing axis from the world swing axis
	 * `worldSwingAxis`, and returns `this`.
	 */
	public init(rigidBody1:RigidBody, rigidBody2:RigidBody, worldAnchor:Vec3, worldTwistAxis:Vec3, worldSwingAxis:Vec3):RagdollJointConfig {
		this._init(rigidBody1, rigidBody2, worldAnchor);
		rigidBody1.getLocalVectorTo(worldTwistAxis, this.localTwistAxis1);
		rigidBody2.getLocalVectorTo(worldTwistAxis, this.localTwistAxis2);
		rigidBody1.getLocalVectorTo(worldSwingAxis, this.localSwingAxis1);
		return this;
	}

}
